package com.woniu.user.controller;


import com.woniu.common.ResponseData;
import com.woniu.common.dto.UserDTO;
import com.woniu.common.dto.UserRoleDTO;
import com.woniu.user.entity.Face;
import com.woniu.user.entity.result.FaceResult;
import com.woniu.user.service.FaceService;
import com.woniu.user.service.UserService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {

    @Autowired
    private UserService userService;
    @Autowired
    private FaceService faceService;

    @PostMapping("/init")
    public ResponseData<?> init(){
        return userService.init();
    }
    @PostMapping("/vef")
    @ApiOperation(value="人脸验证", notes="根据传入的base64编码和数据的base64编码进行对比")

    public ResponseData<?> faceVef(@RequestBody String imageBase){
        return faceService.vef(imageBase);
    }

    @PostMapping("/register")
    @ApiOperation(value="注册", notes="根据传入的手机号和验证码进行注册")
    public ResponseData<?> register(@RequestBody UserDTO userDTO){
        return userService.register(userDTO);
    }

    @PostMapping("/phoneLogin")
    @ApiOperation(value="手机号登录", notes="根据传入的手机号和密码进行登录")
    public ResponseData<?> phoneLogin(@RequestBody UserDTO userDTO){
        return userService.phoneLogin(userDTO);
    }

    @PostMapping("/codeLogin")
    @ApiOperation(value="验证码登录", notes="根据传入的手机号和验证码进行登录")
    public ResponseData<?> codeLogin(@RequestBody UserDTO userDTO){
        return userService.codeLogin(userDTO);
    }
    @PostMapping("/codeLoginApp")
    @ApiOperation(value="验证码登录", notes="根据传入的手机号和验证码进行登录")
    public ResponseData<?> codeLoginApp(@RequestBody UserDTO userDTO){
        return userService.registerApp(userDTO);
    }



    @GetMapping("/getCode/{phoneNum}")
    @ApiOperation(value="获取验证码", notes="根据传入的手机号获取验证码")
    public ResponseData<?> getCode(@PathVariable("phoneNum") String phoneNum){
        return userService.getCode(phoneNum);
    }


    @PostMapping("/changePassword")
    @ApiOperation(value = "修改密码",notes = "根据原密码修改密码")
    public ResponseData<?> changePassword(@RequestBody UserDTO userDTO){
        return userService.changePassword(userDTO);
    }

    @PostMapping("/checkUser")
    @ApiOperation(value = "判断用户是否存在",notes = "根据数据库数据查询")
    public ResponseData<?> checkUser(@RequestBody UserDTO userDTO){
        return userService.checkUser(userDTO);
    }

    @PostMapping("/queryAllUserRole")
    @ApiOperation(value = "查询所有用户角色",notes = "根据数据库数据查询")
    public ResponseData<?> queryAllUserRole(){
        return userService.queryAllUserRole();
    }


    @PostMapping("/updateUserRole")
    @ApiOperation(value = "修改用户角色",notes = "根据数据库数据查询")
    public ResponseData<?> updateUserRole(@RequestBody UserRoleDTO userDTO){
        return userService.updateUserRole(userDTO);
    }




}
